require(quadprog)
require(corpcor)
nameEst <- function(cond, targ){
	Y <- targ
	X <- cond
	Yt <- Y
	orderind <- intersect(names(Yt), rownames(X))
	Yt <- Yt[orderind]
	X <- X[orderind,]
	Yt <- Yt[row.names(X)]
	designmat <- model.matrix(Yt ~ -1 + X)
	Dmat <- crossprod(designmat, designmat)
	pdind <- is.positive.definite(Dmat)
	if(pdind == FALSE){Dmat <- make.positive.definite(Dmat)}
	dvec <- crossprod(designmat, Yt)
	#Amat <- cbind(1, diag(nrow(Dmat)))
	#bvec <- c(1, rep(0, nrow(Dmat)))
	Amat <- cbind(
    matrix(1, nr=length(dvec), nc=1),
    diag(length(dvec)),
    -diag(length(dvec))
  	)
	bvec <- c(1, rep(0, length(dvec)), rep(-1, length(dvec)))
	meq <- 1
	resTmp <- tryCatch(expr = solve.QP(Dmat, dvec, Amat, bvec, meq, factorized = F)[[1]], error = function(e) rep(NA, ncol(X)))
	out <- round(resTmp, 5)
	names(out) <- colnames(X)
	return(out)
}